package com.david.musicapp

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log

class HeadsetPlugReceiver: BroadcastReceiver() {
    override fun onReceive(context:Context,  intent: Intent) {
        if (intent.hasExtra("state")){
            if (intent.getIntExtra("state", 0) == 0){
//                Toast.makeText(context, "headset not connected", Toast.LENGTH_LONG).show();
                val serviceIntent = Intent(context, PlayService::class.java)
                intent.putExtra(PlayService.SONG_ACTION_TYPE_KEY, PlayService.SONG_ACTION_TYPE_PAUSE)
                context.startService(serviceIntent)
            } else if (intent.getIntExtra("state", 0) == 1){
//                Toast.makeText(context, "headset connected", Toast.LENGTH_LONG).show();
                Log.e("music", "headset connected")
            }
        }

    }

}